package com.example.librarymanagementsystembackend.systemicfunctions.service;

import com.example.librarymanagementsystembackend.bookmanagement.entity.BookInformation;
import com.example.librarymanagementsystembackend.bookmanagement.mapper.BookMapper;
import com.example.librarymanagementsystembackend.systemicfunctions.entity.SystemSettingsEntity;
import com.example.librarymanagementsystembackend.systemicfunctions.mapper.SystemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class SystemService {

    //导入SystemMapper类
    @Autowired
    private SystemMapper systemMapper;

    @Autowired
    private BookMapper bookMapper;

    private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    //查询借阅的基础信息
    public int updateParameters(int borrowLimit, int borrowPeriod, BigDecimal dailyOverdueFine) {
        return systemMapper.updateParameters(borrowLimit, borrowPeriod, dailyOverdueFine);
    }

    //查询系统的配置
    public SystemSettingsEntity getSystemSettings(){
        return systemMapper.getSystemSettings();
    }

    //更改用户的头像和背景颜色
    public int updateUserExpansionInformation(int id,String avatarUrl,String backgroundColor){
        return systemMapper.updateUserExpansionInformation(id, avatarUrl, backgroundColor);
    }

    //更改用户的名称和密码
    public int userBasicInformation(int id,String username,String password){
        return systemMapper.updateUserBasicInformation(id,username,passwordEncoder.encode(password));
    }

    //查询图书信息
    public List<BookInformation> bookInformation(){
        return bookMapper.getAllBooks();
    }
}
